﻿using BluetoothMachine.Domains;
using BluetoothMachine.GlobalStatics;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;

namespace BluetoothMachine.ViewModels.DialogHostsModel
{
    public class LoginDialogsViewModel : INotifyPropertyChanged
    {
        public string Name { get; set; }
        /// <summary>
        /// 登录消息
        /// </summary>
        public string LoginMessage { get; set; }
        /// <summary>
        /// 文本延时
        /// </summary>
        public Brush TextBrush { get; set; }

        public LoginDialogsViewModel()
        {

        }

        public DelegateCommand<PasswordBox> Login => new DelegateCommand<PasswordBox>(async password =>
        {
            TextBrush = Brushes.Black;
            LoginMessage = $"登陆中，请等待...";
            var global = ServiceDiscovery.ResolveSingleton<UserGlobal>();
            if (await global.Login("admin", password.Password)) DialogHost.CloseDialogCommand.Execute(new object(), password);
            else { LoginMessage = $"登录失败，账号或密码错误"; TextBrush = Brushes.Red; }
        });

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
